ALMaSS  1.0
The Animal, Landscape and Man Simulation System
Hunters_all.h
Go to the documentation of this file.
1 /*
2 *******************************************************************************************************
3 Copyright (c) 2013, Christopher John Topping, University of Aarhus
4 All rights reserved.
5 
6 Redistribution and use in source and binary forms, with or without modification, are permitted provided
7 that the following conditions are met:
8 
9 Redistributions of source code must retain the above copyright notice, this list of conditions and the
10 following disclaimer.
11 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
12 the following disclaimer in the documentation and/or other materials provided with the distribution.
13 
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
15 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
17 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
18 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
19 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 ********************************************************************************************************
23 */
32 //---------------------------------------------------------------------------
33 #ifndef HuntersH
34 #define HuntersH
35 //---------------------------------------------------------------------------
36 class Hunter;
38 class Field;
39 
40 //------------------------------------------------------------------------------
41 
45 typedef enum
46 {
50 
56 {
62 };
63 
69 {
70  hlm_shoot = 0,
73 } ;
74 
80 {
81  public:
82  int m_ref;
83  int m_HType;
85  vector <int> m_huntlocrefs;
86  vector <APoint> m_huntlocs;
87  unsigned m_no_hunt_locs;
89  vector<Farm*> m_farms;
91  int m_weekend;
92  double m_efficiency;
96 };
97 
98 
103 {
106 };
107 
111 typedef vector < Hunter* > HunterList;
112 
120 class Hunter : public TAnimal
121 {
122 protected:
123  // Attributes
125  int m_myname;
131  int m_clock;
133  int m_bag;
147  double m_efficiency;
153  vector<Farm*> m_OurFarmers;
161  vector <int> m_HuntLocRefs;
163  vector <APoint> m_HuntLocs;
164 
165  // Methods
167  virtual TypeOfHunterState st_ShouldGoHunting( void );
169  TypeOfHunterState st_OutHunting( void ); // Must be overridden in descendent classes;
173  virtual void Init(struct_Hunter* p_data);
175  bool IsTodayAPreferredHuntDay( int a_today );
177  bool IsTodayAChosenHuntDay( int a_today );
179  virtual int CheckForGame( void ) {
180  return false;
181  }
182 
183 public:
187  virtual ~Hunter();
190  return m_huntingdays;
191  }
193  int GetBag() {
194  return m_bag;
195  }
197  int GetShots() {
198  return m_myShots;
199  }
201  virtual void ResetBag() {
202  m_bag = 0;
203  m_myShots = 0;
204  }
207  m_huntingdays = 0;
208  }
210  int GetClock() {
211  return m_clock;
212  }
214  void ResetClock() {
215  m_clock = 0;
216  }
219  ResetBag();
221  }
223  bool IsOutHunting() {
224  if (m_CurrentHState == tohts_OutHunting) return true;
225  return false;
226  }
230  int GetRef() { return m_myname; }
232  APoint GetHome() { return m_Home; }
234  int GetHuntField() {
235  return m_huntfield_polyref;
236  }
238  APoint GetHuntLoc(unsigned a_ref) { return m_HuntLocs[a_ref]; }
240  Farm* GetFarmerRef(unsigned a_ref) { return m_OurFarmers[a_ref]; }
242  virtual bool InSeason( int /* day */ ) {
243  return false;
244  }
246  virtual bool IsSeasonEnd( int /* day */ ) {
247  return true;
248  }
250  virtual int GetSeasonLengthLeft( int /* day */ ) {
251  return 0;
252  }
254  virtual void SaveMyData( ofstream* /* a_ofile */ ) {
255  ; // Base class does nothing
256  }
258  virtual void OnShoot() { ; }
260  virtual void OnGoHome(){ ; }
261 
262 };
263 
268 class GooseHunter : public Hunter
269 {
270 protected:
271 // Attributes
277  bool m_dugin;
285  bool m_leader;
286 // Methods
288  virtual void Init();
290  virtual bool InSeason( int day );
292  virtual bool IsSeasonEnd( int day );
294  virtual int GetSeasonLengthLeft( int day );
300  bool FindHuntingLocation( void );
302  virtual int CheckForGame( void );
304  virtual void OnShoot();
306  virtual void OnGoHome();
307 public:
308 // Methods
312  virtual ~GooseHunter();
314  virtual void Step();
316  void OnShotABird( int a_birdtype, int a_poly );
318  virtual void SaveMyData( ofstream* a_ofile );
320  virtual void ResetBag() {
322  for (int i = 0; i < gst_foobar; i++) m_goosebag[ i ] = 0;
323  }
325  bool IsLeader() {
326  return m_leader;
327  }
328 };
329 
335 {
336 public:
337  // Methods
341  virtual ~Hunter_Population_Manager (void);
343  void Init(void);
345  void DistributeHunters(void);
347  void DistributeHuntersByRules( vector<HunterInfo> *a_hunterlist, int a_no_hunters, int a_ruleset );
349  void RuleSet10Based( int a_no_hunters, vector<int>* a_farmsizes, vector<HunterInfo>* a_hunterlist, vector<APoint>* a_roostlocs, int a_ruleset );
351  void SaveDistributedHunters( vector<HunterInfo>* a_hunterlist, int a_no_hunters );
353  void SaveFarmHunters( vector<HunterInfo>* a_hunterlist, int a_no_hunters );
355  void CreateObjects(int ob_type, TAnimal*, struct_Hunter* data,int number);
357  void RecordHuntingSuccess(int poly,int birds, int a_hunter);
359  APoint GetHunterHome(int a_index, int a_list);
361  APoint GetHunterHuntLoc(int a_index, int a_list, unsigned a_ref);
363  unsigned GetNoHuntLocs();
365  bool CheckDensity(int a_ref, vector<int> *a_illegalfarms, vector<FarmOccupcancyData>* a_FarmOccupancy);
367  bool AddHunterHunting( int a_polyref, Hunter* a_hunter );
369  void HunterLeaderMessage(TypeOfHunterLeaderMessage a_signal, int a_polyref);
371  vector<HunterList*> m_ActiveHuntingLocationsHunters;
375  bool IsPolyrefOnActiveList( int a_polyref );
377  void SetHuntingSeason();
382 
383 protected:
384  // Attributes
386  unsigned m_daytime;
393 
394 
395  // Methods
396  virtual bool StepFinished() { return true; }
398  virtual void DoFirst();
400  virtual void DoBefore(){}
402  virtual void DoAfter(){}
404  virtual void DoLast(){}
405 };
406 
407 //---------------------------------------------------------------------------
408 #endif
@ gst_foobar
Definition: Goose_Base.h:66
TypeOfHunterState
Hunters like other ALMaSS animals work using a state/transition concept. These are the hunter behavio...
Definition: Hunters_all.h:56
@ tohts_foobar
Definition: Hunters_all.h:61
@ tohts_OutHunting
Definition: Hunters_all.h:59
@ tohts_Hunting
Definition: Hunters_all.h:58
@ tohts_Resting
Definition: Hunters_all.h:60
@ tohts_InitialState
Definition: Hunters_all.h:57
TTypeOfHunters
Definition: Hunters_all.h:46
@ toh_GooseHunter
Definition: Hunters_all.h:47
@ toh_foobar
Definition: Hunters_all.h:48
vector< Hunter * > HunterList
Definition: Hunters_all.h:111
TypeOfHunterLeaderMessage
Types of message a hunter leader can pass on to team members.
Definition: Hunters_all.h:69
@ hlm_gohome
Definition: Hunters_all.h:71
@ hlm_shoot
Definition: Hunters_all.h:70
@ hlm_foobar
Definition: Hunters_all.h:72
A simple class defining an x,y coordinate set.
Definition: ALMaSS_Setup.h:53
The base class for all farm types.
Definition: farm.h:768
Definition: elements.h:728
The class to handle all goose population related matters.
Definition: Goose_Population_Manager.h:393
The class for goose hunters encompsassing all their specific behaviours.
Definition: Hunters_all.h:269
virtual void ResetBag()
Sets the annual hunting bag to zero.
Definition: Hunters_all.h:320
virtual ~GooseHunter()
GooseHunter destructor.
Definition: Hunters_all.cpp:1207
virtual void OnGoHome()
On gohome message handler.
Definition: Hunters_all.cpp:1438
bool IsLeader()
Returns the leader flag.
Definition: Hunters_all.h:325
virtual void Step()
GooseHunter Step code.
Definition: Hunters_all.cpp:1446
virtual bool InSeason(int day)
Is it goose hunting season? - MUST be overridden in descendent class.
Definition: Hunters_all.cpp:1271
void OnShotABird(int a_birdtype, int a_poly)
Message received when a goose is successully shot.
Definition: Hunters_all.cpp:1413
bool FindHuntingLocation(void)
Locate the hunt for today.
virtual int CheckForGame(void)
If the hunter checks for game at their hunting locations then this is done here. Must be overridden.
Definition: Hunters_all.cpp:1231
bool m_dugin
Flag to show whether a hunting location has been found.
Definition: Hunters_all.h:277
bool m_leader
When hunting this indicates whether the hunter is a team leader.
Definition: Hunters_all.h:285
virtual bool IsSeasonEnd(int day)
Is it the end of the goose hunting season? - MUST be overridden in descendent class.
Definition: Hunters_all.cpp:1260
virtual int GetSeasonLengthLeft(int day)
Returns the length of the hunting season in days - MUST be overridden in descendent class.
Definition: Hunters_all.cpp:1296
virtual void OnShoot()
On shoot message handler.
Definition: Hunters_all.cpp:1419
int m_pinkfootbaglimit
Bag limit for pinkfoot.
Definition: Hunters_all.h:281
int m_goosebag[gst_foobar]
A special bag data structure so the hunter knows what kind of geese he shot.
Definition: Hunters_all.h:279
int m_greylagbaglimit
Bag limit for greylag.
Definition: Hunters_all.h:283
virtual void SaveMyData(ofstream *a_ofile)
Each hunter needs to save different kinds of data, so we use a polymorphic method for this.
Definition: Hunters_all.cpp:1469
GooseHunter(struct_Hunter *p_data, Hunter_Population_Manager *p_PPM)
GooseHunter constructor.
Definition: Hunters_all.cpp:1197
virtual TypeOfHunterState st_ShouldGoHunting(void)
Behavior involved in deciding whether to go hunting.
Definition: Hunters_all.cpp:1315
polylist * m_huntfields
Our list of possible hunting fields as polygon reference numbers as supplied by Landscape::SupplyPoly...
Definition: Hunters_all.h:275
virtual void Init()
Initiation of a specific goose hunter here.
Definition: Hunters_all.cpp:1212
Goose_Population_Manager * m_preyPopulationManger
Pointer to our game population, the geese.
Definition: Hunters_all.h:273
TypeOfHunterState st_OutHunting(void)
The basic hunting behaviour.
Definition: Hunters_all.cpp:1332
The class to handle all predator population related matters.
Definition: Hunters_all.h:335
APoint GetHunterHome(int a_index, int a_list)
Returns the hunter home location.
Definition: Hunters_all.cpp:1016
Hunter_Population_Manager(Landscape *p_L)
Hunter population manager constructor.
Definition: Hunters_all.cpp:119
virtual void DoFirst()
Does general daily tasks e.g. reset time of day, reset bag lists if start of year etc....
Definition: Hunters_all.cpp:947
virtual ~Hunter_Population_Manager(void)
Hunter population manager destructor.
Definition: Hunters_all.cpp:141
bool AddHunterHunting(int a_polyref, Hunter *a_hunter)
Adds a hunter hunting, returns true if that hunter is the leader otherwise false.
Definition: Hunters_all.cpp:1478
virtual void DoAfter()
Available for hunter management - not used currently.
Definition: Hunters_all.h:402
void HunterLeaderMessage(TypeOfHunterLeaderMessage a_signal, int a_polyref)
A message system to rely messages from the leader hunter to others in his team.
Definition: Hunters_all.cpp:1027
int m_HuntingSeasonEnd
End of the overall hunting season.
Definition: Hunters_all.h:392
APoint GetHunterHuntLoc(int a_index, int a_list, unsigned a_ref)
Returns the hunter hunting location location.
Definition: Hunters_all.cpp:1021
bool IsPolyrefOnActiveList(int a_polyref)
Debugging check method.
Definition: Hunters_all.cpp:1059
virtual void DoLast()
Available for hunter management - not used currently.
Definition: Hunters_all.h:404
unsigned GetNoHuntLocs()
Calculates the number of hunting locations based on a distribution.
Definition: Hunters_all.cpp:186
ofstream * m_HuntingBagRecord
Output file for hunting bag record.
Definition: Hunters_all.h:388
bool CheckDensity(int a_ref, vector< int > *a_illegalfarms, vector< FarmOccupcancyData > *a_FarmOccupancy)
helper method to reduce code size in hunter rules - checks density rules
Definition: Hunters_all.cpp:300
void RuleSet10Based(int a_no_hunters, vector< int > *a_farmsizes, vector< HunterInfo > *a_hunterlist, vector< APoint > *a_roostlocs, int a_ruleset)
Used to implement rule sets based on rule set 10.
Definition: Hunters_all.cpp:800
int m_HuntingSeasonStart
Start of the overall hunting season.
Definition: Hunters_all.h:390
int GetHuntingSeasonEnd()
Get the end of the overall hunting season.
Definition: Hunters_all.h:381
vector< int > m_ActiveHuntingLocationsPolyrefs
Lists of polygon reference numbers for all active hunting locations (updated daily)
Definition: Hunters_all.h:373
void SaveDistributedHunters(vector< HunterInfo > *a_hunterlist, int a_no_hunters)
Saves the results of the hunter distribution to an output file.
Definition: Hunters_all.cpp:198
void DistributeHuntersByRules(vector< HunterInfo > *a_hunterlist, int a_no_hunters, int a_ruleset)
Implements the rule sets to distributes hunters to hunting locations (farms).
Definition: Hunters_all.cpp:346
void DistributeHunters(void)
Distributes hunters to hunting locations (farms).
Definition: Hunters_all.cpp:151
virtual void DoBefore()
Available for hunter management - not used currently.
Definition: Hunters_all.h:400
void CreateObjects(int ob_type, TAnimal *, struct_Hunter *data, int number)
Creates hunter objects and assigns them to the population manager lists.
Definition: Hunters_all.cpp:925
unsigned m_daytime
Used to follow the time of day in 10 minute steps.
Definition: Hunters_all.h:386
vector< HunterList * > m_ActiveHuntingLocationsHunters
Lists of hunters at all active hunting locations (updated daily)
Definition: Hunters_all.h:371
int GetHuntingSeasonStart()
Get the start of the overall hunting season.
Definition: Hunters_all.h:379
void SaveFarmHunters(vector< HunterInfo > *a_hunterlist, int a_no_hunters)
Saves the results of the hunter distribution to an output file by farm.
Definition: Hunters_all.cpp:233
void RecordHuntingSuccess(int poly, int birds, int a_hunter)
Hunting bag output.
Definition: Hunters_all.cpp:1002
void Init(void)
Create the initial hunter population and initializes any output options.
Definition: Hunters_all.cpp:837
virtual bool StepFinished()
Overrides the population manager StepFinished - there is no chance that hunters do not finish a step ...
Definition: Hunters_all.h:396
void SetHuntingSeason()
This returns the number of geese which are legal quarry on the polygon the day before.
Definition: Hunters_all.cpp:1498
The base class for hunters encompsassing all their general behaviours.
Definition: Hunters_all.h:121
Hunter_Population_Manager * m_OurPopulationManager
Pointer to the population manager.
Definition: Hunters_all.h:129
virtual ~Hunter()
The destructor for the Hunter class.
Definition: Hunters_all.cpp:1081
int m_baglimit
Annual self-imposed limit on number shot - unused at present.
Definition: Hunters_all.h:143
vector< int > m_HuntLocRefs
Definition: Hunters_all.h:161
virtual bool IsSeasonEnd(int)
Is it the end of the hunting season? - MUST be overridden in descendent class.
Definition: Hunters_all.h:246
int m_weekend
Code for weekly hunting activity.
Definition: Hunters_all.h:151
TypeOfHunterState st_Resting(void)
Finished hunting and waiting for the next opportunity.
Definition: Hunters_all.cpp:1185
double m_goosecountchance
Probability of checking for geese in hunting area.
Definition: Hunters_all.h:149
int GetHuntField()
Get the polygon reference number to our current hunting field (which is at a hunting location)
Definition: Hunters_all.h:234
int m_myname
A reference number unique to this hunter.
Definition: Hunters_all.h:125
int GetShots()
Gets the number of shots this season to-date.
Definition: Hunters_all.h:197
Farm * GetFarmerRef(unsigned a_ref)
Provide our ref name.
Definition: Hunters_all.h:240
virtual void SaveMyData(ofstream *)
Each hunter needs to save different kinds of data, so we use a polymorphic method for this.
Definition: Hunters_all.h:254
vector< APoint > m_HuntLocs
Definition: Hunters_all.h:163
bool IsTodayAPreferredHuntDay(int a_today)
Checks for the hunting day preference (weekday or any day)
Definition: Hunters_all.cpp:1137
APoint GetHuntLoc(unsigned a_ref)
Provide our hunting location coords.
Definition: Hunters_all.h:238
TypeOfHunterState m_CurrentHState
The current hunter behavioural state.
Definition: Hunters_all.h:127
APoint m_Home
Definition: Hunters_all.h:155
virtual int GetSeasonLengthLeft(int)
Returns the length of the hunting season in days - MUST be overridden in descendent class.
Definition: Hunters_all.h:250
virtual void OnShoot()
On shoot message handler - must be overidden in descendent classes.
Definition: Hunters_all.h:258
virtual void ResetBag()
Sets the annual hunting bag to zero.
Definition: Hunters_all.h:201
void ResetHuntingOpportunities()
Sets the annual hunting attempts count to zero.
Definition: Hunters_all.h:206
int m_lasthuntday
The date for the last hunt day.
Definition: Hunters_all.h:141
double m_efficiency
Probability of 'hitting' a game item.
Definition: Hunters_all.h:147
APoint GetHome()
Provide our home coords.
Definition: Hunters_all.h:232
void ResetSeasonData()
Sets the bag and hunting counters to zero.
Definition: Hunters_all.h:218
int GetHuntingDays()
Gets the annual hunting attempts count.
Definition: Hunters_all.h:189
virtual int CheckForGame(void)
If the hunter checks for game at their hunting locations then this is done here. Must be overridden.
Definition: Hunters_all.h:179
vector< Farm * > m_OurFarmers
List of pointers to the farmers whose land the hunter hunts
Definition: Hunters_all.h:153
bool IsTodayAChosenHuntDay(int a_today)
Uses a probability test to determine whether to go hunting today.
Definition: Hunters_all.cpp:1158
int m_myShots
The numbers of shots to-date this year.
Definition: Hunters_all.h:135
int GetBag()
Gets the annual hunting bag.
Definition: Hunters_all.h:193
int m_myMagazine
The number of shells in the magazine.
Definition: Hunters_all.h:137
int GetClock()
Supplies the clock time.
Definition: Hunters_all.h:210
virtual TypeOfHunterState st_ShouldGoHunting(void)
Decide whether to go out hunting on a specific day.
Definition: Hunters_all.cpp:1109
virtual bool InSeason(int)
Is it hunting season? - MUST be overridden in descendent class.
Definition: Hunters_all.h:242
int m_huntfield_polyref
The polygon reference number to our current hunting field (which is at a hunting location)
Definition: Hunters_all.h:157
Hunter(struct_Hunter *p_data, Hunter_Population_Manager *p_PPM)
The constructor for the Hunter class.
Definition: Hunters_all.cpp:1075
virtual void Init(struct_Hunter *p_data)
Initiation of a basic hunter here.
Definition: Hunters_all.cpp:1086
bool IsOutHunting()
A debug function, but may be useful in other contexts. Returns true of currently out hunting.
Definition: Hunters_all.h:223
TypeOfHunterState st_OutHunting(void)
The basic hunting behaviour.
Definition: Hunters_all.cpp:1177
int m_huntlimit
Annual self-imposed limit on number of days spent hunting.
Definition: Hunters_all.h:145
int m_bag
The numbers of game items shot todate this year.
Definition: Hunters_all.h:133
int GetRef()
Provide our ref name.
Definition: Hunters_all.h:230
int m_NoHuntLocs
Definition: Hunters_all.h:159
int m_huntingdays
The numbers of days used for hunting this year.
Definition: Hunters_all.h:139
void ResetClock()
Sets the clock back to zero.
Definition: Hunters_all.h:214
virtual void OnGoHome()
On gohome message handler - must be overidden in descendent classes.
Definition: Hunters_all.h:260
void OnMorning()
Optimism in the morning, perhaps we should hunt?
Definition: Hunters_all.h:228
int m_clock
Records the time spent hunting per day.
Definition: Hunters_all.h:131
The landscape class containing all environmental and topographical data.
Definition: landscape.h:113
Base class for all population managers.
Definition: PopulationManager.h:424
The base class for all ALMaSS animal classes.
Definition: PopulationManager.h:205
Used for creation of a new hunter object.
Definition: Hunters_all.h:80
double m_goosecountchance
Definition: Hunters_all.h:93
unsigned m_no_hunt_locs
Definition: Hunters_all.h:87
double m_efficiency
Definition: Hunters_all.h:92
int m_HType
Definition: Hunters_all.h:83
int m_ref
Definition: Hunters_all.h:82
int m_huntingdayslimit
Definition: Hunters_all.h:90
vector< int > m_huntlocrefs
Definition: Hunters_all.h:85
APoint m_validxy
Definition: Hunters_all.h:88
Landscape * m_L
Definition: Hunters_all.h:94
vector< APoint > m_huntlocs
Definition: Hunters_all.h:86
Population_Manager * m_preyPM
Definition: Hunters_all.h:95
APoint m_home
Definition: Hunters_all.h:84
int m_weekend
Definition: Hunters_all.h:91
vector< Farm * > m_farms
Definition: Hunters_all.h:89
vector< unsigned > polylist
Definition: farm.h:207
Definition: Hunters_all.h:103
int m_no_hunters
Definition: Hunters_all.h:105
int m_FarmRef
Definition: Hunters_all.h:104